/*******************************************************************************
 *
 *    The information contained herein is the exclusive property of
 *  Sunplus app Technology Co. Ltd. And shall not be distributed, reproduced,
 *  or disclosed in whole in part without prior written permission.
 *
 *           (C) COPYRIGHT 2008-2014  Sunplus app Technology Co. Ltd.
 *                            ALL RIGHTS RESERVED
 *
 *    The entire notice above must be reproduced on all authorized copies.
 *
 *******************************************************************************
 *
 * Description: C++ plugin for main.qml
 * Others:      None.
 * Function List:
 *   1) SystemUtils::run()
 *        Run a program, called by main.qml
 *
 * History:
 *   v1.0       Lijian<lijian@sunplusapp.com>
 *     1) Add xxx and xxx functions.
 *     2) fix some bug of function XXXX.
 *
 *   v0.1       Lijian<lijian@sunplusapp.com>
 *     1) created.
 *
 ******************************************************************************/
#ifndef SYSTEMUTILS_H
#define SYSTEMUTILS_H

#include <QObject>
#include <QVariant>
#include <QStringList>
#include <QDeclarativeListProperty>
#include <QAbstractListModel>

class QSocketNotifier;
class SystemUtils : public QObject
{
    Q_OBJECT
    QStringList _bgList;
    QString _bg;
    //QVariantList _iconPageLists;
    QString _iconPageListFilePath;
#ifndef _WIN32
    int _inotify_fd;
    int _watch_fd;
    QSocketNotifier *_inotify_nodifier;
#endif
public:
    explicit SystemUtils(QObject *parent = 0);
    ~SystemUtils();

    Q_PROPERTY(QStringList backgrounds READ backgrounds NOTIFY backgroundsChanged)
    const QStringList &backgrounds() const { return _bgList; }

    Q_PROPERTY(QString background READ background NOTIFY backgroundChanged)
    const QString &background() const { return _bg; }

    Q_PROPERTY(QString iconPageLists READ iconPageLists NOTIFY iconPageListsChanged)
    QString iconPageLists() const;

    /***********************************************************
     * Name: SystemUtils::run
     * Description: run a program
     * Arguments:
     *   [IN] QString cmd - program name or path
     *   [IN] QString arg - program arguments
     * Return:
     *   None
     * Others:
     *
     **********************************************************/
    Q_INVOKABLE void run(const QString &cmd, const QString &arg);

signals:
    void backgroundsChanged();
    void backgroundChanged();
    void iconPageListsChanged();

private slots:
    void onWatchTriggered();
};

#endif // SYSTEMUTILS_H
